package com.netty.zhanglong.thrift;

import com.netty.thrift.generated.Person;
import com.netty.thrift.generated.PersonService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

/**
 * Description:
 *
 * @author: StriverFeng
 * @date: 2018-10-4
 * Details:
 */
public class ThriftClient {
    public static void main(String[] args) {
        TTransport transport=new TFramedTransport(new TSocket("localhost",8899),600);
        TProtocol protocol = new TCompactProtocol(transport);
        PersonService.Client client=new PersonService.Client(protocol);
        try {
            transport.open();
            Person person = client.getPersonByUsername("张三");
            System.out.println(person.getUsername());
            System.out.println(person.getAge());
            System.out.println(person.isMarried());
            System.out.println("-----------------------");
            Person person2=new Person();
            person2.setUsername("李四");
            person2.setAge(20);
            person2.setMarried(true);
            client.savePerson(person2);
        }catch (Exception ex){
            throw  new RuntimeException(ex.getMessage(),ex);
        } finally {
            transport.close();
        }
    }
}
